//
//  JCBillSectionHeaderView.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/5/18.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCBillSectionHeaderView.h"

@interface JCBillSectionHeaderView()

@property (nonatomic, strong) UIView * bgView;

@property (nonatomic, strong) UIImageView * amountImage;

@property (nonatomic, strong) UILabel * withholdLabel;// 代扣金额

@property (nonatomic, strong) UILabel * amount;// 金额（代扣）

@property (nonatomic, strong) UILabel * timeLabel;// 时间

@end

@implementation JCBillSectionHeaderView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self initUI];//_init表示初始化方法
    }
    
    return self;
}
//+ (instancetype)headerVierWithTableView:(UITableView *)tableView{
//    static NSString * ID = @"JCBillSectionHeaderView";
//    JCBillSectionHeaderView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ID];
//    if (headerView == nil) {
//        headerView = [[JCBillSectionHeaderView alloc] initWithReuseIdentifier:ID];
//    }
//    
//    return headerView;
//}

- (void)initUI{
    
    self.contentView.backgroundColor = [UIColor colorWithHexString:@"#F5F9FC"];
    
    self.bgView = [UIView new];
    self.bgView.backgroundColor = [UIColor colorWithHexString:@"#54B0F7"];
    [self.contentView addSubview:self.bgView];
    
    self.amountImage = [UIImageView new];
    self.amountImage.image = [UIImage imageNamed:@"amount"];
    [self.bgView addSubview:self.amountImage];
    
    self.withholdLabel = [UILabel new];
    self.withholdLabel.textColor = [UIColor colorWithHexString:@"#ffffff"];
    self.withholdLabel.font = KSHSystemFont(14);
    self.withholdLabel.text = @"代扣金额:";
    [self.bgView addSubview:self.withholdLabel];
    
    self.amount = [UILabel new];
    self.amount.textColor = [UIColor colorWithHexString:@"#ffffff"];
    self.amount.font = KSHSystemFont(14);
//    self.amount.text = @"2038元";
    [self.bgView addSubview:self.amount];
    
    self.timeLabel = [UILabel new];
    self.timeLabel.textColor = [UIColor colorWithHexString:@"#ffffff"];
    self.timeLabel.font = KSHSystemFont(14);
    self.timeLabel.textAlignment = NSTextAlignmentRight;
//    self.timeLabel.text = @"2018/05/19";
    [self.bgView addSubview:self.timeLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(__I6Height(10));
        make.height.mas_offset(__I6Height(34));
    }];
    [self.amountImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__I6Width(15));
        make.centerY.equalTo(self.bgView);
        make.width.height.mas_offset(__I6Width(20));
    }];

    [self.withholdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.amountImage.mas_right).offset(__I6Width(10));
        make.centerY.equalTo(self.bgView);
        make.top.bottom.equalTo(self.bgView);
    }];

    [self.amount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.withholdLabel.mas_right).offset(2);
        make.centerY.equalTo(self.bgView);
    }];

    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView).offset(-__I6Width(15));
        make.centerY.equalTo(self.bgView);
    }];
    
    //得到view的遮罩路径
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5,5)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bgView.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.bgView.layer.mask = maskLayer;
}

- (void)getAmount:(NSString *)strAmount andDate:(NSString *)strDate{
    self.timeLabel.text = strDate;
    self.amount.text = strAmount;
}



@end
